package base.File路径;

import java.io.File;
import java.util.HashMap;
import java.util.function.BiConsumer;

public class 文件类型个数 {
    public static int n = 0;
    public static void main(String[] args) {
       File src = new File("D:\\");
       HashMap<String,Integer> mp = new HashMap<>();
       statistics(src,mp);

       mp.forEach(new BiConsumer<String, Integer>() {
           @Override
           public void accept(String s, Integer integer) {
               if (n % 2 ==0){
                   System.out.println();
               }
               System.out.print(s+"="+integer+"\t\t");
               n++;
           }
       });
    }

    public static void statistics(File src,HashMap<String,Integer> mp){
        File[] files = src.listFiles();
        if (files != null){
            for (File file : files) {
                if (file.isFile()){
                    String[] str = file.getName().split("\\.");
                    if (str.length >= 2){
                        String type = str[str.length-1];
                        if (mp.containsKey(type)){
                            int i = mp.get(type);
                            i++;
                            mp.put(type,i);
                        }else {
                            mp.put(type,1);
                        }
                    }
                }else {
                    statistics(file,mp);
                }
            }
        }
    }
}
